home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / lib / mntc6846.zoo / patch / dftosf.s < prev    next >
Encoding:
Text File  |  1994-11-14  |  2.1 KB  |  69 lines

  1.  ! C68 8 byte floating point => 4 byte floating point conversion routine
  2.  !-----------------------------------------------------------------------------
  3.  ! ported to 68000 by Kai-Uwe Bloem, 12/89
  4.  !  #1  original author: Peter S. Housel 06/03/89
  5.  !  #2    added support for denormalized numbers            -kub-, 01/90
  6.  !  #3  Redid register usage, and then added wrapper routine
  7.  !    to provide C68 IEEE compatibility    Dave & Keith Walker    02/92
  8.  !  #4    Changed entry/exit code for C68 v4.3 compatibility
  9.  !    Removed ACK entry points                -djw-    09/93
  10.  !-----------------------------------------------------------------------------
  11.  
  12. SAVEREG = 3*4            ! size of saved registers on stack
  13.  
  14. BIAS4    =    0x7F - 1
  15. BIAS8    =    0x3FF - 1
  16.  
  17.     .sect .text
  18.     .define .Xdftosf
  19.  
  20. !----------------------------------------
  21. !    sp    Return address
  22. !    sp+4    address of result
  23. !    sp+8    address of argument
  24. !----------------------------------------
  25. .Xdftosf:
  26.     movem.l    d2-d4,-(sp)        ! save registers that will be corrupted
  27.     move.l    SAVEREG+8(sp),a0    ! argument address
  28.     move.l    SAVEREG+4(sp),a1    ! result address
  29.  
  30.     move.w    (a0),d0        ! extract exponent
  31.     move.w    d0,d2        ! extract sign
  32.     lsr.w    #4,d0
  33.     and.w    #0x7ff,d0    ! kill sign bit
  34.  
  35.     move.w    d2,d1
  36.     and.w    #0x0f,d1    ! remove exponent from mantissa
  37.     tst.w    d0        ! check for zero exponent - no leading "1"
  38.     beq    0f        ! for denormalized numbers
  39.     or.w    #0x10,d1    ! restore implied leading "1"
  40.     bra    1f
  41. 0:    add.w    #1,d0        ! "normalize" exponent
  42. 1:    move.w    d1,d3        ! store exponent
  43.     swap    d3        ! ... in correct part of register
  44.     move.w    2(a0),d3    ! get next 2 bytes of original value
  45.     move.l    4(a0),d4    ! .. and the last 4 bytes
  46.  
  47.     add.w    #BIAS4-BIAS8,d0    ! adjust bias
  48.  
  49.     add.l    d4,d4        ! shift up to realign mantissa for floats
  50.     addx.l    d3,d3
  51.     add.l    d4,d4
  52.     addx.l    d3,d3
  53.     add.l    d4,d4
  54.     addx.l    d3,d3
  55.     move.l    d3,(a1)        ! write result.mantissa
  56.  
  57.     move.l    d4,d1        ! set rounding bits
  58.     rol.l    #8,d1
  59.     and.l    #0x00ffffff,d4    ! check to see if sticky bit should be set
  60.     beq    2f
  61.     or.b    #1,d1        ! set sticky bit
  62. 2:    jsr    .Xnorm4        ! go to normalise result
  63.  
  64.     movem.l    (sp)+,d2-d4    ! restore saved registers
  65.     move.l    (sp)+,a1    ! get return address
  66.     add.l    #8,sp        ! remove parameters from stack
  67.     jmp    (a1)        ! ... and return
  68.  
  69.